import { createRouter, createWebHistory } from 'vue-router'
import routes from './routes'

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  // 路由跳转始终滚动到头部
  scrollBehavior () {
    // 始终滚动到顶部
    return { top: 0 }
  }
})
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
    next(true)
  } else {
    next(true)
  }
})
export default router
